package View;

import java.sql.*;

public class Database {
//    public void sj() {
    static {
//    try {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
//            Connection c= DriverManager.getConnection("jdbc:mysql://localhost:3306/lxt","root","111111");
//            Statement s=c.createStatement();
//            ResultSet result=s.executeQuery("select *from 教师信息;");
//            while (result.next()){
//                int dc=result.getInt("id");
//                String gh=result.getString("教职工号");
//                String xm=result.getString("姓名");
//                String xb=result.getString("性别");
//                String lx=result.getString("联系方式");
//                System.out.println(result.getString("教职工号")+result.getString("姓名")+result.getString("性别")+result.getString("联系方式"));
//
//            }
//            result.close();
//            s.close();
//            c.close();
    }

//    }
    //获取链接
    public static Connection getConn(){
        try {
           return DriverManager.getConnection("jdbc:mysql://localhost:3306/lxt","root","111111");
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static void closeConn(Connection connection){
        if (connection!=null){
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
    public static void closePs(PreparedStatement ps){
            if (ps!=null){
                try {
                    ps.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
    }
    public static void closeRs(ResultSet rs){
        if (rs!=null){
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

//    public static void main(String[] args) {
//        new shujuku().sj();
//    }

}
